package com.wbt.jdk.io;


import com.wbt.entity.Test;

import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * @program: Thread-demo
 * @description:
 * @author: Wang·Baotong
 * @create: 2021-05-14 09:55
 */
public class StreamTest {

    public static void main(String[] args) throws Exception{

        FileInputStream fis = new FileInputStream("E:\\a.txt");
        byte[] b = new byte[1024];
        int i ;
        while ((i=fis.read(b)) != -1){
            System.out.println(new String(b,0,i));
        }
        fis.close();

        StreamObject();
        pathsTest();
    }

    public static void StreamObject() throws Exception{
        ObjectInputStream ob = new ObjectInputStream(new FileInputStream("E:\\Test.txt"));

        Test t = (Test)ob.readObject();
        System.out.println(t.toString());
    }

    public static void pathsTest() throws Exception{
        Path path = Paths.get("E:\\a.txt");
        byte[] data = Files.readAllBytes(path);
        System.out.println(new String(data,0,data.length));

    }
}
